{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你\n",
      "好\n",
      "p\n",
      "y\n",
      "t\n",
      "h\n",
      "o\n",
      "n\n",
      "！\n",
      "元组：你好\n",
      "元组：pyhotn!\n",
      "列表：你好\n",
      "列表：python!\n",
      "first\n",
      "字典：你好\n",
      "second\n",
      "字典：pyhtone!\n"
     ]
    }
   ],
   "source": [
    "#循环结构 for...in  够简洁，i都不用定义的吗？这个i in XXX好强大。。。\n",
    "char=u'你好python！'\n",
    "tem=('元组：你好','元组：pyhotn!')\n",
    "list=['列表：你好','列表：python!']\n",
    "dict={'first':'字典：你好','second':'字典：pyhtone!'}\n",
    "\n",
    "for i in char:\n",
    "    print(i)\n",
    "for i in tem:\n",
    "    print(i)\n",
    "for i in list:\n",
    "    print(i)\n",
    "for i in dict:\n",
    "    print(i)\n",
    "    print(dict[i])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n",
      "11\n",
      "12\n",
      "13\n",
      "14\n",
      "16\n",
      "17\n",
      "18\n",
      "====\n",
      "10\n",
      "11\n",
      "12\n",
      "13\n",
      "14\n"
     ]
    }
   ],
   "source": [
    "#循环终止语句 break  continue\n",
    "for i in range(10,19):\n",
    "    if i==15:\n",
    "        continue\n",
    "    print(i)\n",
    "print('====')    \n",
    "for i in range(10,19):\n",
    "    if i==15:\n",
    "        break\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3.6.4\n"
     ]
    }
   ],
   "source": [
    "#输出python的版本信息\n",
    "import platform\n",
    "print(platform.python_version())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['20180801', '20180802', '20180803', '20180804', '20180805']\n",
      "['20.51', '3.54', '6.88', '71.5', '100', '66.66']\n"
     ]
    }
   ],
   "source": [
    "#定义日期和股票价格列表 list set--[]    tuple--()   dict--{}\n",
    "date_array=[]\n",
    "date_base=20180801\n",
    "for _ in range(5):\n",
    "    date_array.append(str(date_base))\n",
    "    date_base+=1\n",
    "print(date_array)\n",
    "price_array=['20.51','3.54','6.88','71.5','100','66.66']\n",
    "print(price_array)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[('20180801', '20.51'), ('20180802', '3.54'), ('20180803', '6.88'), ('20180804', '71.5'), ('20180805', '100')]\n",
      "20180803\n",
      "20180801 的价格是 20.51\n",
      "20180802 的价格是 3.54\n",
      "20180803 的价格是 6.88\n",
      "20180804 的价格是 71.5\n",
      "20180805 的价格是 100\n"
     ]
    }
   ],
   "source": [
    "#将股票价格和日期对应起来\n",
    "stock_tuple_list=[(date,price) for date,price in zip(date_array,price_array)]\n",
    "print(stock_tuple_list)\n",
    "\n",
    "#stock_tuple_list[i][0] is date,stock_tuple_list[i][1] is price.\n",
    "print(stock_tuple_list[2][0])\n",
    "\n",
    "#输出每日股票价格\n",
    "for i in range(0,5):\n",
    "    print(stock_tuple_list[i][0],'的价格是',stock_tuple_list[i][1])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[股票(date='20180801', price='20.51'), 股票(date='20180802', price='3.54'), 股票(date='20180803', price='6.88'), 股票(date='20180804', price='71.5'), 股票(date='20180805', price='100')]\n",
      "20180803 的价格是 6.88\n"
     ]
    }
   ],
   "source": [
    "#可命名元组 namedtuple 这里是对元组和其中包含元素进行命名，如下的股票，日期，价格\n",
    "from collections import namedtuple\n",
    "stock_namedtuple=namedtuple('股票',('date','price'))\n",
    "stock_namedtuple_list=[stock_namedtuple(date,price) for date,price in zip(date_array,price_array)]\n",
    "print(stock_namedtuple_list)\n",
    "print(stock_namedtuple_list[2].date,'的价格是',stock_namedtuple_list[2].price)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'20180801': '20.51', '20180802': '3.54', '20180803': '6.88', '20180804': '71.5', '20180805': '100'}\n",
      "dict_keys(['20180801', '20180802', '20180803', '20180804', '20180805']) dict_values(['20.51', '3.54', '6.88', '71.5', '100'])\n",
      "71.5\n",
      "('100', '20180805')\n",
      "('71.5', '20180804')\n"
     ]
    }
   ],
   "source": [
    "#字典推导式\n",
    "stock_dict={date:price for date,price in zip(date_array,price_array)}\n",
    "print(stock_dict)\n",
    "#返回字典所有的key和value\n",
    "print(stock_dict.keys(),stock_dict.values())\n",
    "\n",
    "#提供key值可查找value,提供value值无法查找Key\n",
    "print(stock_dict[date_array[3]])\n",
    "#print(stock_dict[price_array[3]])\n",
    "\n",
    "print(min(zip(stock_dict.values(),stock_dict.keys())))\n",
    "print(max(zip(stock_dict.values(),stock_dict.keys())))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "odict_keys(['20180801', '20180802', '20180803', '20180804', '20180805'])\n"
     ]
    }
   ],
   "source": [
    "from collections import OrderedDict\n",
    "stock_dict= OrderedDict((date,price) for date,price in zip(date_array,price_array))\n",
    "print(stock_dict.keys())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'20180801': '20.51', '20180802': '3.54', '20180803': '6.88', '20180804': '71.5', '20180805': '100'}\n",
      "('100', '20180805')\n",
      "('71.5', '20180804')\n",
      "<class 'dict_values'>\n"
     ]
    }
   ],
   "source": [
    "#函数\n",
    "print(stock_dict)\n",
    "print(min(zip(stock_dict.values(),stock_dict.keys())))\n",
    "print(max(zip(stock_dict.values(),stock_dict.keys())))\n",
    "print(type(stock_dict.values()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function len in module builtins:\n",
      "\n",
      "len(obj, /)\n",
      "    Return the number of items in a container.\n",
      "\n",
      "None\n"
     ]
    }
   ],
   "source": [
    "print(help(len))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function abs in module builtins:\n",
      "\n",
      "abs(x, /)\n",
      "    Return the absolute value of the argument.\n",
      "\n",
      "None\n"
     ]
    }
   ],
   "source": [
    "print(help(abs))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
